<template>
	<view class="detail-wrap">
		<view class="detail-container" v-if="id">
			 <tn-list-view :card="true" unlined="top">
			      <tn-list-cell v-for="item in caseStaticInfo">
					  <text class="cell-left">
					  	{{ item.name }}：
					  </text>
					  <text class="cell-right">
					  	{{ caseData[item.prop] || "无" }}
					  </text>
				  </tn-list-cell>
			</tn-list-view>
			<view class="fixed">
				<tn-button v-if="!hasVisit"  backgroundColor="#3D7EFF" fontColor="#ffffff"  @click="visitFunc()">去回访</tn-button>
				<tn-button v-else backgroundColor="#3D7EFF" fontColor="#ffffff"  @click="visitFunc()">回访详情</tn-button>
			</view>
		</view>
		<view class="detail-empty" v-else>
			 <tn-empty mode="cart" icon="empty-search" iconColor="#CC5A36" text="未取到信息,请返回重试!"></tn-empty>
		</view>
	</view>
</template>

<script>
import { caseDetailLib } from './utils/dict.js';
import { caseDetail,getVisitList } from '@/api/visit.js';
import { shiguliexing } from '@/static/mock/shiguliexing.js';
	export default {
	    data() {
	        return {
				hasVisit: false,
	            id: '',
				caseStaticInfo:[],
				caseData: {},
				isVist: false,
	        };
	    },
	    onLoad(options) {
			this.id = options.id;
			console.log(this.id);
			this.hasVisit = Number(options.hasVisit);
			this.caseStaticInfo = [...[],...caseDetailLib];
	    },
		onShow() {
			if(this.id != ''){
				this.getCaseData();
			}else{
				console.log('未获取到案件id');
			}
		},
		methods: {
			//获取详情数据
			getCaseData(){
				caseDetail({
					id: this.id
				}).then((res) => {
					let obj = res.data;
					this.caseData = obj;
					try {
						this.caseData.kNum_mNum = `K${obj.kNum} + ${obj.mNum}`
						// this.caseData.callDepart = `${obj.callDepart === 1?"已通知":"未通知"}`
						this.caseData.caseType =  shiguliexing.find(item=>item.caseTypeId === obj.caseTypeId)['label']
					} catch (error) {
						//TODO handle the exception
					}
					
				}).finally(()=>{
					//uni.stopPullDownRefresh()
				});
			},
			//跳转回访页面
			visitFunc(){
				uni.navigateTo({
					url: '/pages/visit/visit?id='+this.id + "&hasVisit=" + this.hasVisit
				});
			},
		}
	};
</script>

<style lang="scss" scoped>
	.fixed{
		position: fixed;
		bottom: 20rpx;
		left: 50%;
		transform: translateX(-50%);
	}
	.detail-empty{
		margin-top: 12rem;
	}
	.detail-container{
		padding: 0 .6rem;
	}
	.cell-left{
		font-weight: 500;
		margin-right: .6rem;
	}
	.cell-right{
		font-size: 32rpx;
		color: #666;
	}
</style>